<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入解析ConcurrentHashMap - Java并发编程精髓</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-radius: 0.5rem;
            padding: 1.5rem;
            position: relative;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 12px;
            left: 12px;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #ef4444;
            box-shadow: 20px 0 0 #f59e0b, 40px 0 0 #10b981;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .section-divider {
            border-top: 1px solid #e2e8f0;
            margin: 4rem 0;
            position: relative;
        }
        .section-divider::after {
            content: attr(data-title);
            position: absolute;
            top: -0.7rem;
            left: 50%;
            transform: translateX(-50%);
            background-color: #f8fafc;
            padding: 0 1rem;
            color: #64748b;
            font-weight: 600;
            font-size: 0.875rem;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <div class="mb-6 bg-gradient-to-r from-blue-500 to-indigo-600 text-white inline-flex items-center justify-center px-4 py-2 rounded-full text-sm font-medium">
                    <i class="fas fa-lock-open mr-2"></i> Java并发编程
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-6">深入解析ConcurrentHashMap</h1>
                <p class="text-xl text-blue-100 max-w-3xl mb-10">
                    揭秘Java并发编程中最重要集合类的设计哲学与实现细节，从分段锁到CAS优化，打造高性能并发系统的核心武器。
                </p>
                <div class="flex flex-wrap justify-center gap-4">
                    <a href="#overview" class="bg-white text-blue-600 font-semibold px-6 py-3 rounded-lg hover:bg-blue-50 transition duration-300">
                        <i class="fas fa-book-open mr-2"></i>开始阅读
                    </a>
                    <a href="#applications" class="bg-blue-600 bg-opacity-20 text-white font-semibold px-6 py-3 rounded-lg hover:bg-opacity-30 transition duration-300">
                        <i class="fas fa-laptop-code mr-2"></i>应用场景
                    </a>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <div class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover transition duration-300">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-100 text-blue-600 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                        <i class="fas fa-exclamation-triangle text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">Java开发者的并发困境</h2>
                </div>
                <p class="text-gray-700 mb-4">
                    Java攻城狮们！有没有遇到过这样的场景：正当你信心满满地用HashMap处理用户登录信息时，产品经理突然告诉你："系统需要支持10万并发用户"，然后你的代码就开始"裂开"了？
                </p>
                <p class="text-gray-700">
                    当多线程环境与HashMap相遇，我们的程序就如同一场灾难片：数据错乱、CPU飙升、间歇性空指针异常，甚至JDK 7下出现无限循环导致CPU 100%。面试官最爱问的问题之一也是："HashMap是线程安全的吗？如果不是，你会怎么解决？"
                </p>
            </div>

            <div class="bg-white rounded-xl shadow-lg p-8 card-hover transition duration-300">
                <div class="flex items-center mb-6">
                    <div class="bg-green-100 text-green-600 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                        <i class="fas fa-shield-alt text-xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold">ConcurrentHashMap的救赎</h2>
                </div>
                <p class="text-gray-700">
                    ConcurrentHashMap就像一位身披铠甲的武士，专门为并发环境设计，它不仅线程安全，而且性能远胜于用synchronized包装的HashMap。然而，很多开发者虽然每天都在使用它，却对其内部机制知之甚少。
                </p>
            </div>
        </div>

        <!-- Section Divider -->
        <div class="section-divider" data-title="并发安全设计原理"></div>

        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">1. 并发安全设计概览</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 text-purple-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-history"></i>
                        </div>
                        <h3 class="text-xl font-bold">1.1 从"全表锁"到"分段锁"再到"CAS+Synchronized"</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        在讲解ConcurrentHashMap之前，让我们先看看Java中并发安全的Map实现是如何演进的：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>// 第一代：使用同步包装器，全表锁
Map&lt;String, Data&gt; userMap = Collections.synchronizedMap(new HashMap<>());

// 第二代：JDK 5引入的ConcurrentHashMap，分段锁
Map&lt;String, Data&gt; userCache = new ConcurrentHashMap<>(); // JDK 7及以前

// 第三代：JDK 8重新设计的ConcurrentHashMap，CAS+Synchronized
Map&lt;String, Data&gt; userMetrics = new ConcurrentHashMap<>(); // JDK 8及以后</code></pre>
                    </div>
                    <p class="text-gray-700 mb-4">
                        这三代实现的性能差距有多大？测试表明，ConcurrentHashMap在高并发下的性能通常是同步Map的3-5倍！
                    </p>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-yellow-100 text-yellow-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-road"></i>
                        </div>
                        <h3 class="text-xl font-bold">演变历程可视化</h3>
                    </div>
                    <div id="evolution-chart" class="mermaid">
                        timeline
                            title ConcurrentHashMap 演变历程
                            section JDK 1.4及以前
                                全表锁 : 2002: Collections.synchronizedMap
                            section JDK 5
                                分段锁 : 2004: ConcurrentHashMap
                            section JDK 8
                                CAS+Synchronized : 2014: 全新设计
                    </div>
                    <p class="text-gray-700 mt-4">
                        从全表锁到分段锁再到CAS+Synchronized，每一步演进都是为了在高并发环境下提供更好的性能表现。
                    </p>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 text-blue-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-puzzle-piece"></i>
                        </div>
                        <h3 class="text-xl font-bold">1.2 JDK 7中的分段锁设计</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        JDK 7的ConcurrentHashMap采用了分段锁(Segment)的设计，将数据分为若干段，每一段配一把锁：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>// JDK 7 ConcurrentHashMap简化结构
public class ConcurrentHashMap&lt;K, V&gt; extends AbstractMap&lt;K, V&gt; 
    implements ConcurrentMap&lt;K, V&gt; {
    // 将整个Map分成多段（默认16段）
    final Segment&lt;K,V&gt;[] segments;
    
    static final class Segment&lt;K,V&gt; extends ReentrantLock {
        transient volatile HashEntry&lt;K,V&gt;[] table;
        // ...其他字段和方法
    }
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这种设计就像高速公路收费站，不再只有一个收费口（全表锁），而是有多个收费口（Segment）同时工作，大大提高了并发效率。
                    </p>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 text-green-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h3 class="text-xl font-bold">1.3 JDK 8中的CAS+Synchronized方案</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        JDK 8彻底重写了ConcurrentHashMap，摒弃了分段锁设计，转而采用CAS+Synchronized的机制：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>// JDK 8 ConcurrentHashMap简化结构
public class ConcurrentHashMap&lt;K,V&gt; extends AbstractMap&lt;K,V&gt; {
    // 存储数据的数组
    transient volatile Node&lt;K,V&gt;[] table;
    
    static class Node&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; {
        final int hash;
        final K key;
        volatile V val;
        volatile Node&lt;K,V&gt; next;
        // ...方法实现
    }
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这就像是收费站升级了设备，不再设置固定的收费口，而是根据车流量实时调整，每个车道都能快速处理并收费，大大提升了通行效率。
                    </p>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider" data-title="核心数据结构"></div>

        <!-- Data Structure Section -->
        <section id="structure" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">2. 核心数据结构与实现</h2>
            
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover transition duration-300">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-600 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-2xl font-bold">2.1 Node及其变种</h3>
                </div>
                <p class="text-gray-700 mb-6">
                    JDK 8的ConcurrentHashMap使用了多种特殊节点类型，就像一支训练有素的特种部队，每个成员都有不同的专长：
                </p>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <div class="flex items-start mb-4">
                            <div class="bg-blue-100 text-blue-600 rounded-lg p-2 mr-3">
                                <i class="fas fa-link"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-lg">Node</h4>
                                <p class="text-gray-600">基本节点，构成链表</p>
                            </div>
                        </div>
                        <div class="flex items-start mb-4">
                            <div class="bg-green-100 text-green-600 rounded-lg p-2 mr-3">
                                <i class="fas fa-forward"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-lg">ForwardingNode</h4>
                                <p class="text-gray-600">扩容时的标记节点，指向新表</p>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="flex items-start mb-4">
                            <div class="bg-yellow-100 text-yellow-600 rounded-lg p-2 mr-3">
                                <i class="fas fa-tree"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-lg">TreeNode</h4>
                                <p class="text-gray-600">红黑树节点，用于优化长链表</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-100 text-purple-600 rounded-lg p-2 mr-3">
                                <i class="fas fa-map-marker-alt"></i>
                            </div>
                            <div>
                                <h4 class="font-bold text-lg">ReservationNode</h4>
                                <p class="text-gray-600">临时占位节点</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-red-100 text-red-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-key"></i>
                        </div>
                        <h3 class="text-xl font-bold">2.2 哈希算法与桶分配</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        ConcurrentHashMap使用的哈希算法与HashMap类似，但在并发环境下更加关注性能：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>static final int spread(int h) {
    return (h ^ (h >>> 16)) & HASH_BITS;
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这个方法将键的hashCode的高16位与低16位进行异或，然后屏蔽最高位（防止负数哈希），确保哈希值分布均匀。
                    </p>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 text-purple-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-lock"></i>
                        </div>
                        <h3 class="text-xl font-bold">2.3 头结点锁定机制</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        JDK 8的ConcurrentHashMap在put操作时使用了头结点锁定机制：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>final V putVal(K key, V value, boolean onlyIfAbsent) {
    // 计算哈希值
    int hash = spread(key.hashCode());
    // 自旋，直到成功插入
    for (Node&lt;K,V&gt;[] tab = table;;) {
        // 目标位置为空，CAS插入新节点
        if ((f = tabAt(tab, i)) == null) {
            if (casTabAt(tab, i, null, newNode))
                break;
        }
        // 锁定头结点f
        synchronized (f) {
            // 处理节点...
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider" data-title="关键操作解析"></div>

        <!-- Operations Section -->
        <section id="operations" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">3. 关键操作源码分析</h2>
            
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover transition duration-300">
                <div class="flex items-center mb-6">
                    <div class="bg-blue-100 text-blue-600 rounded-full w-12 h-12 flex items-center justify-center mr-4">
                        <i class="fas fa-download"></i>
                    </div>
                    <h3 class="text-2xl font-bold">3.1 put操作的并发实现</h3>
                </div>
                <p class="text-gray-700 mb-6">
                    put操作是ConcurrentHashMap中最复杂的操作之一，它展示了多种并发控制技术的综合运用：
                </p>
                <div class="code-block text-gray-200 mb-4">
                    <pre><code>final V putVal(K key, V value, boolean onlyIfAbsent) {
    // 1. 先尝试无锁CAS操作（目标桶为空时）
    // 2. 只有在必要时才加锁，且仅锁定相关的桶
    // 3. 对扩容操作进行了特殊处理
    // 4. 支持链表到红黑树的转换
}</code></pre>
                </div>
                <p class="text-gray-700">
                    这种细粒度的锁定策略大大提高了并发效率。就像现代高速公路的ETC系统，大部分车辆可以不停车快速通过，只有特殊情况才需要停下处理。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 text-green-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-search"></i>
                        </div>
                        <h3 class="text-xl font-bold">3.2 get操作的无锁设计</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        ConcurrentHashMap的get操作是完全无锁的，这也是其高性能的重要原因：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>public V get(Object key) {
    // 1. Node的value和next指针都是volatile的，保证了可见性
    // 2. 哈希表的结构只会在put和remove等写操作中改变
    // 3. 不变的键和不可变的哈希值保证了正确性
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这是并发编程中的一个重要思想：读操作尽可能不加锁，通过内存可见性保证正确性。
                    </p>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-yellow-100 text-yellow-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-expand"></i>
                        </div>
                        <h3 class="text-xl font-bold">3.3 resize操作的协作机制</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        ConcurrentHashMap的扩容操作支持多线程协作完成：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>private final void transfer(Node&lt;K,V&gt;[] tab, Node&lt;K,V&gt;[] nextTab) {
    // 1. 多线程协作扩容，每个线程负责一部分桶
    // 2. 使用ForwardingNode标记已处理的桶
    // 3. 节点要么留在原位置，要么移动到原位置+oldCap
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这种设计就像一个高效的搬家团队，多人协作，有明确的分工，而且会在已搬完的房间留下标记。
                    </p>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider" data-title="性能优化策略"></div>

        <!-- Optimization Section -->
        <section id="optimization" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">4. 并发性能优化策略</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 text-indigo-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-book-reader"></i>
                        </div>
                        <h3 class="text-xl font-bold">4.1 读操作完全无锁</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        ConcurrentHashMap的读操作是完全无锁的，这带来了几个好处：
                    </p>
                    <ul class="list-disc pl-5 text-gray-700 space-y-2">
                        <li>读操作不会阻塞其他线程</li>
                        <li>多个读操作可以并行执行</li>
                        <li>读操作不会与写操作互相排斥</li>
                    </ul>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 text-purple-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-people-carry"></i>
                        </div>
                        <h3 class="text-xl font-bold">4.2 分段并发扩容</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        扩容通常是HashMap类最耗时的操作，ConcurrentHashMap的创新之处在于将扩容任务分解，由多个线程共同完成：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>final Node&lt;K,V&gt;[] helpTransfer(Node&lt;K,V&gt;[] tab, Node&lt;K,V&gt; f) {
    // 线程在执行put/remove时，如果发现表正在扩容就帮忙
}</code></pre>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 text-blue-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-atom"></i>
                        </div>
                        <h3 class="text-xl font-bold">4.3 CAS操作减少锁竞争</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        ConcurrentHashMap大量使用CAS操作来减少锁竞争：
                    </p>
                    <div class="code-block text-gray-200 mb-4">
                        <pre><code>static final &lt;K,V&gt; boolean casTabAt(Node&lt;K,V&gt;[] tab, int i,
                                 Node&lt;K,V&gt; c, Node&lt;K,V&gt; v) {
    return U.compareAndSwapObject(tab, i, c, v);
}</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 text-green-600 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                            <i class="fas fa-tree"></i>
                        </div>
                        <h3 class="text-xl font-bold">4.4 红黑树优化大哈希桶性能</h3>
                    </div>
                    <p class="text-gray-700 mb-4">
                        当哈希桶中的链表长度超过阈值（默认为8）时，ConcurrentHashMap会将链表转换为红黑树：
                    </p>
                    <div class="code-block text-gray-200">
                        <pre><code>private final void treeifyBin(Node&lt;K,V&gt;[] tab, int index) {
    // 如果表太小，优先扩容而不是树化
    // 否则将链表转换为红黑树
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Section Divider -->
        <div class="section-divider" data-title="实际应用场景"></div>

        <!-- Applications Section -->
        <section id="applications" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">5. 实际应用场景分析</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex justify-center mb-4 text-blue-600">
                        <i class="fas fa-database text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-center mb-3">5.1 高并发缓存系统</h3>
                    <p class="text-gray-700 mb-4">
                        使用ConcurrentHashMap实现简单的本地缓存，支持高并发读取和写入：
                    </p>
                    <div class="code-block text-gray-200 text-sm">
                        <pre><code>public class SimpleCache&lt;K, V&gt; {
    private final ConcurrentHashMap&lt;K, V&gt; cache;
    private final ConcurrentHashMap&lt;K, Long&gt; expiry;
    // 实现过期清理等高级功能
}</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex justify-center mb-4 text-green-600">
                        <i class="fas fa-tasks text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-center mb-3">5.2 异步任务管理器</h3>
                    <p class="text-gray-700 mb-4">
                        管理大量并发提交的任务，支持任务取消和状态查询：
                    </p>
                    <div class="code-block text-gray-200 text-sm">
                        <pre><code>public class TaskManager {
    private final ConcurrentHashMap&lt;String, CompletableFuture&lt;?&gt;&gt; tasks;
    // 实现任务提交、取消等功能
}</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg p-6 card-hover transition duration-300">
                    <div class="flex justify-center mb-4 text-purple-600">
                        <i class="fas fa-network-wired text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-bold text-center mb-3">5.3 分布式系统的本地路由表</h3>
                    <p class="text-gray-700 mb-4">
                        维护服务实例的路由信息，支持高并发的服务发现和负载均衡：
                    </p>
                    <div class="code-block text-gray-200 text-sm">
                        <pre><code>public class ServiceRouter {
    private final ConcurrentHashMap&lt;String, List&lt;ServiceInstance&gt;&gt; routeTable;
    // 实现服务注册、发现等功能
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Card -->
        <div class="bg-gradient-to-r from-indigo-500 to-blue-600 rounded-xl shadow-lg p-8 text-white">
            <div class="flex items-start">
                <div class="bg-white bg-opacity-20 rounded-full w-14 h-14 flex items-center justify-center mr-5 flex-shrink-0">
                    <i class="fas fa-lightbulb text-2xl"></i>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-3">关键设计思想总结</h3>
                    <ul class="list-disc pl-5 space-y-2">
                        <li><strong>空间换时间</strong>：用额外空间减少锁竞争</li>
                        <li><strong>降低锁粒度</strong>：从全表锁到分段锁再到桶锁</li>
                        <li><strong>避免不必要的锁</strong>：读操作完全无锁设计</li>
                        <li><strong>乐观并发策略</strong>：先尝试CAS，失败时再加锁</li>
                    </ul>
                </div>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white">技术小馆</h3>
                    <p class="text-gray-400">分享有价值的技术知识</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300">
                        <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <!-- Mermaid.js -->
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: { useMaxWidth: false }
        });
    </script>
</body>
</html>